import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent, STPage } from '@delon/abc/table';
import { SFSchema, SFComponent, SFRadioWidgetSchema } from '@delon/form';
import { LbWjfwComponent } from '@shared/components/lb_wjfw/lbwjfw.component';
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';
import { ActivatedRoute } from '@angular/router';
import { ReuseTabService } from '@delon/abc';
import { NzMessageService } from 'ng-zorro-antd';
import { SupDic, HttpService } from 'lbf';

@Component({
  selector: 'app-zyjk-zrbli',
  templateUrl: './zrbli.component.html',
})
export class ZyjkZrbliComponent implements OnInit {
  tabs = ['办件信息', '材料影像'];
  dataset = [];
  PROJID = '1';
  DAD069 = '';
  fordated: any = {};
  fordated1: any = {};
  isVisible = false;
  daealb = [];
  asdas = '1200px';

  params = { sname: 'BJXX_QUERY', queryparas: {} };

  slSchema: SFSchema = {
    properties: {
      DAD095: {
        type: 'string',
        title: '',
        enum: [
          { label: '受理', value: '1' },
          { label: '不受理', value: '0' },
        ],
        // tslint:disable-next-line: no-object-literal-type-assertion
        ui: {
          widget: 'radio',
          // asyncData: () => of().pipe(delay(100)),
          change: console.log,
          grid: {
            span: 24,
          },
        } as SFRadioWidgetSchema,
        default: '1',
      },
      DAD098: {
        type: 'string',
        title: '不予受理原因',
        ui: {
          visibleIf: { DAD095: ['0'] },
          spanLabelFixed: 150,
          grid: { span: 24 },
        },
      },
    },
    ui: { grid: { span: 24 } },
    required: ['DAD098'],
  };

  constructor(
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
    private supDic: SupDic,
    private reuseTabService: ReuseTabService,
    private activateroute: ActivatedRoute,
  ) {
    this.reuseTabService.title = '基本医疗保险转入办理';
  }

  bjxxSchema: SFSchema = {
    properties: {
      AAC002: {
        type: 'string',
        title: '身份证号',
        readOnly: true,
      },

      AAC003: {
        type: 'string',
        title: '姓名',
        readOnly: true,
      },

      AAB301: {
        type: 'string',
        title: '转入地行政区划代码',
        enum: this.supDic.getSFDic('AAB301'),
        readOnly: true,
      },
      AAC027: {
        type: 'string',
        title: '转出地行政区划代码',
        readOnly: true,
      },

      AAE040: {
        title: '参保（合）起时间',
        type: 'string',
        format: 'YYYYMM',
        readOnly: true,
        ui: { widget: 'date', displayFormat: 'yyyy/MM', size: 'large' },
      },
      AAE041: {
        title: '参保（合）止时间',
        type: 'string',
        readOnly: true,
        format: 'YYYYMM',
        ui: { widget: 'date', displayFormat: 'yyyy/MM', size: 'large' },
      },
      BAB459: {
        title: '累计缴费月数',
        type: 'string',
        readOnly: true,
      },
      AIC089: {
        title: '历年转出资金',
        type: 'number',
        minimum: 0,
        ui: {
          widgetWidth: 210,
          onlyVisual: true,
        },
      },
      AIC082: {
        title: '当年转出资金',
        type: 'number',
        minimum: 0,
        ui: {
          onlyVisual: true,
          widgetWidth: 210,
        },
      },
      AIC102: {
        title: '转移基金总额',
        type: 'number',
        minimum: 0,
        ui: {
          onlyVisual: true,
          widgetWidth: 210,
        },
      },
      AAE035: {
        title: ' 转移日期',
        type: 'string',
        format: 'YYYYMMDD',
        ui: {
          widget: 'date',
          displayFormat: 'yyyy/MM/dd',
          size: 'large',
          onlyVisual: true,
        },
      },
      AAE013: {
        title: '备注',
        type: 'string',
        // ui: {
        //   grid: { span: 12 }
        // }
      },
    },
    ui: {
      spanLabelFixed: 150,
      grid: { span: 8 },
    },

    required: ['AIC089', 'AIC082', 'AIC102', 'AAE035'],
  };

  // 业务编辑区

  bjxxSchema1: SFSchema = {
    properties: {
      AAB301: {
        title: '行政区划代码',
        type: 'string',
        ui: { hidden: true },
      },
      AAE041: {
        title: '开始年月',
        type: 'string',
        maxLength: 6,
        ui: {
          onlyVisual: true,
        },
      },
      AAE042: {
        title: '结束年月',
        type: 'string',
        maxLength: 6,
        ui: {
          onlyVisual: true,
        },
      },
      AAE202: {
        title: '缴费月数',
        type: 'number',
        minimum: 0,
        ui: {
          onlyVisual: true,
          widgetWidth: 268,
        },
      },

      AKC069: {
        title: '已转帐户余额',
        type: 'number',
        default: '0',
        ui: {
          onlyVisual: true,
          widgetWidth: 210,
          hidden: true,
        },
      },
      AAE381: {
        title: '未转帐户余额',
        type: 'number',
        default: '0',
        ui: {
          onlyVisual: true,
          widgetWidth: 300,
          hidden: true,
        },
      },
      AAC072: {
        title: '对方社保',
        type: 'string',
        ui: { hidden: true },
      },
      AAE013: {
        title: '备注',
        type: 'string',
      },
    },
    ui: {
      grid: { span: 24 },
      spanLabelFixed: 80,
    },
    required: [
      'AAB301',
      'AAE041',
      'AAE042',
      'AAE202',
      'AKC069',
      'AAE381',
      'AAC072',
    ],
  };

  tabMode = 'bjxx';
  @ViewChild('bbst', { static: false }) bbst: SFComponent;
  @ViewChild('st', { static: false }) st: STComponent;
  @ViewChild('lbst', { static: false }) lbst: STComponent;
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('slxx', { static: false }) slxx: SFComponent;
  @ViewChild('wjfw', { static: false }) wjfw: LbWjfwComponent;
  @ViewChild('step', { static: true }) step: LbStepsComponent;

  clsmcolumns: STColumn[] = [
    { title: '序号', index: 'RN', width: '10%' },
    { title: '材料名称', index: 'STUFFNAME', width: '50%' },
    { title: '材料数量', index: 'STUFFNUM', width: '25%' },
    { title: '收件类型', index: 'STUFFTYPE', width: '15%' },
  ];

  lbcolumns: STColumn[] = [
    { title: '行政区代码', index: 'AAB301', width: '10%' },
    { title: '', index: 'AAB302', width: '5%' },
    { title: '开始年月', index: 'AAE041', width: '10%' },
    { title: '结束年月', index: 'AAE042', width: '10%' },
    { title: '缴费月数', index: 'AAE202', width: '10%' },
    { title: '已转帐户余额', index: 'AKC069', width: '10%' },
    { title: '未转帐户余额', index: 'AAE381', width: '10%' },
    { title: '对方社保', index: 'AAC072', width: '25%' },
    { title: '备注', index: 'AAE013', width: '15%' },
  ];
  page: STPage = {
    show: false,
  };

  ngOnInit() {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 打开情况下再次传入值
  _onReuseInit(): void {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 事项进度
  selectTab(str: string) {
    this.tabMode = str;
    if (str === 'sxjd') {
    }
  }

  // 界面赋值
  YB_QUERY() {
    this.lbservice
      .lbservice('YB_QUERY', { para: { PROJID: this.PROJID } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.fordated = JSON.parse(resdata.message);
          this.kk();
          this.cha();
          this.sf.reset();
        }
      });
  }

  // 材料列表
  YBCL_QUERY() {
    this.lbservice
      .lbservice('YBCL_QUERY', {
        para: { PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataset = resdata.message.list;
        }
      });
  }

  // 受理保存
  lc_insert(value1: any) {
    // tslint:disable-next-line: all
    if (value1.DAD095 == '0') {
      if (!this.slxx.valid) {
        return this.msgSrv.error('没有填写必填项');
      }
      this.lbservice
        .lbservice('YB_zr_blsave', {
          para: {
            PROJID: this.PROJID,
            sf: this.sf.value,
            slxx: this.slxx.value,
            lbst: this.daealb,
            DAD069: this.DAD069,
          },
        })
        .then(resdata => {
          if (resdata.code < 1) {
            this.msgSrv.error(resdata.errmsg);
          } else {
            this.msgSrv.info('保存成功');
            this.sf.formData = null;
            this.slxx.formData = null;
            this.slxx.reset();
            this.sf.reset();
          }
        });
    } else {
      this.lbservice
        .lbservice('YB_zr_blsave', {
          para: {
            PROJID: this.PROJID,
            sf: this.sf.value,
            slxx: this.slxx.value,
            lbst: this.daealb,
            DAD069: this.DAD069,
          },
        })
        .then(resdata => {
          if (resdata.code < 1) {
            this.msgSrv.error(resdata.errmsg);
          } else {
            this.msgSrv.info('保存成功');
            this.sf.formData = null;
            this.slxx.formData = null;
            this.slxx.reset();
            this.sf.reset();
          }
        });
    }
  }
  // 处理 转出 地
  kk() {
    this.lbservice
      .lbservice('zctcq_a', {
        para: { sf: this.fordated },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.fordated.AAC027 = resdata.message.list[0].AAA103;
          this.sf.reset();
        }
      });
  }
  // 新增
  das() {
    this.isVisible = true;
  }
  //
  saveeCancel(value: any) {
    if (!this.bbst.valid) {
      return this.msgSrv.error('没有填写必填项');
    }

    this.lbservice
      .lbservice('p_g_dsgxx', {
        para: { bbst: value, sf: this.sf.value, PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.isVisible = false;
          this.bbst.reset();
          this.cha();
        }
      });

    this.isVisible = false;
  }
  cha() {
    this.lbservice
      .lbservice('p_xxgxx', {
        para: { PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.daealb = resdata.message.list;

          this.lbst.reset();
        }
      });
  }
  handleCancel() {
    this.isVisible = false;
  }
  // tslint:disable-next-line: member-ordering
  pl = {
    pname: '省端转入数据',
    active: true,
    pname1: '编辑区',
    active1: false,
  };
  // tslint:disable-next-line:all
  icon1 = 'caret-right';
  // tslint:disable-next-line: member-ordering
}
